#include <iostream>
using namespace std;
#include <cstring>
#include <cerrno>
#include <unistd.h>
#include <fcntl.h>

bool SetNonBlock(int fd)
{
  int f1 = fcntl(fd , F_GETFL);
  if (f1 < 0)
  {
    return false;
  }
  fcntl(fd , F_SETFL , f1 | O_NONBLOCK);
  return true;
}

int main()
{
  SetNonBlock(0);
  char buff[1024];

  while (true)
  {
    ssize_t s = read(0 , buff , sizeof(buff)-1);

    if (s > 0)
    {
      buff[s] = 0;
      cout << "echo# " << buff << endl;
    }
    else 
    {
      sleep(1);
      cout << "read \"error\" " << "error: " << errno << "strerrno: " << strerror(errno) << endl;
    }
  }
  return 0;
}
